<?php
namespace Library;
use Library\Request;
use Library\Config;
use Library\Common;
use Library\Response;

class Interceptor extends Request
{
	protected $isInterceptor;
	
	protected $_SERVER;
	
	public function __construct($_SERVERS,$_POSTS,$_GETS,$_REQUESTS){
		$this->_SERVER = $_SERVERS;
		//	执行拦截成功
		$this->implementInterceptor();
	}
	
	
	
	//	执行拦截
	public function implementInterceptor(){
		$classPath = $this->obtainModel()."/Interceptor"."/Index";

		$classPath = str_replace("/","\\",$classPath);
		
		if ( class_exists($classPath) ){
			$res = $classPath::handle((object)$this->_SERVER);
			
			if (empty($res)){
				return new Route($this->_SERVER["PATH_INFO"]);
			}
			
			new Response($res);
			
			exit;
		}else{
			echo "拦截器不存在";
		}
	}
	
	//	得到模块
	public function obtainModel(){
		if ( empty($this->_SERVER["PATH_INFO"]) ){
			$this->_SERVER["PATH_INFO"] = "";
		}
		$this->_SERVER["PATH_INFO"] = Common::completePath($this->_SERVER["PATH_INFO"]);
	
		$rePathInfo = Common::rePath($this->_SERVER["PATH_INFO"]);
		return "/app/".ucfirst($rePathInfo["pathArray"][1]);
	}
}
?>